//package com.example.jooqdemo.config.jooq;
//
//import com.alibaba.druid.pool.DruidDataSourceFactory;
//import org.jooq.DSLContext;
//import org.jooq.SQLDialect;
//import org.jooq.impl.DataSourceConnectionProvider;
//import org.jooq.impl.DefaultConfiguration;
//import org.jooq.impl.DefaultDSLContext;
//import org.jooq.impl.DefaultExecuteListenerProvider;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
//import org.springframework.transaction.PlatformTransactionManager;
//
//import javax.sql.DataSource;
//import java.io.InputStream;
//import java.util.Properties;
//
///**
// * @description: 第二种配置 jooq 方法，以静态代码块创建 jooq 配置，若使用此类，要注释掉JooqConfig类，这两个只能有一个
// * @author: czw
// * @date: 2018/5/23
// */
//@Configuration
//public class Jooq2Config {
//
//    private static DefaultDSLContext dslContext;
//
//    private static DataSource dataSource;
//
//    private static DataSourceTransactionManager txm;
//
//    static {
//        InputStream in = null;
//        in = Jooq2Config.class.getClassLoader().getResourceAsStream("application.properties");
//        Properties props = new Properties();
//        try {
//            props.load(in);
//            dataSource = DruidDataSourceFactory.createDataSource(props);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
//        transactionManager.setDataSource(dataSource);
//        txm = transactionManager;
//        SpringTransactionProvider springTransactionProvider = new SpringTransactionProvider(transactionManager);
//        DataSourceConnectionProvider connectionProvider = new DataSourceConnectionProvider(new TransactionAwareDataSourceProxy(dataSource));
//
//        DefaultConfiguration configuration = new DefaultConfiguration();
//        configuration.set(connectionProvider);
//        configuration.set(springTransactionProvider);
//        configuration.set(new DefaultExecuteListenerProvider(new JooqToSpringTransformer()));
//        configuration.set(SQLDialect.MYSQL);
//        //配置执行监听器
//        configuration.set(DefaultExecuteListenerProvider.providers(new SlowQueryListener()));
//
//        dslContext = new DefaultDSLContext(configuration);
//    }
//
//
//    public static DSLContext getDslContext() {
//        return dslContext;
//    }
//
//    @Bean
//    public PlatformTransactionManager platformTransactionManager() {
//        return txm;
//    }
//
////    /**
////     * 如果想使用 自动注入 DSLContext 可以将此代码解除注释，但带来的问题是导致项目启动变慢
////     * @return
////     */
////    @Bean
////    public DSLContext dslContext(){
////        return dslContext;
////    }
//
//}